package com.zjpavt.taiyuan.service.deviceImageInfo;

import com.alibaba.dubbo.config.annotation.Service;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zjpavt.taiyuan.dao.DeviceImageInfoMapper;
import com.zjpavt.taiyuan.model.DeviceImageInfo;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Auther: zhuliangyu
 * @Date: 2019/10/10 13:23
 * @Description:
 */
@Component
public class DeviceImageInfoServiceImpl extends ServiceImpl<DeviceImageInfoMapper,DeviceImageInfo> implements DeviceImageInfoService {
	@Resource
	private DeviceImageInfoMapper deviceImageInfoMapper;

	private DeviceImageInfoSo entity2so(DeviceImageInfo deviceImageInfo){
		DeviceImageInfoSo deviceImageInfoSo = new DeviceImageInfoSo();
		deviceImageInfoSo.setDeviceId(deviceImageInfo.getDeviceId());
		deviceImageInfoSo.setDeviceImage(deviceImageInfo.getDeviceImage());
		deviceImageInfoSo.setDeviceName(deviceImageInfo.getDeviceName());
		deviceImageInfoSo.setProjectImage(deviceImageInfo.getProjectImage());
		return deviceImageInfoSo;
	}
	private DeviceImageInfo so2entity(DeviceImageInfoSo deviceImageInfoSo){
		DeviceImageInfo deviceImageInfo = new DeviceImageInfo();
		deviceImageInfo.setDeviceId(deviceImageInfoSo.getDeviceId());
		deviceImageInfo.setDeviceImage(deviceImageInfoSo.getDeviceImage());
		deviceImageInfo.setDeviceName(deviceImageInfoSo.getDeviceName());
		deviceImageInfo.setProjectImage(deviceImageInfoSo.getProjectImage());
		return deviceImageInfo;
	}
	@Override
	public List<DeviceImageInfoSo> selectAll() {
		List<DeviceImageInfo> deviceImageInfos = deviceImageInfoMapper.selectList(Wrappers.emptyWrapper());
		List<DeviceImageInfoSo>deviceImageInfoSos = new ArrayList<>();
		for (DeviceImageInfo deviceImageInfo : deviceImageInfos) {
			deviceImageInfoSos.add(entity2so(deviceImageInfo));
		}
		return deviceImageInfoSos;
	}

	@Override
	public DeviceImageInfoSo selectByDeviceId(String deviceId) {
		DeviceImageInfo deviceImageInfo = deviceImageInfoMapper.selectById(deviceId);
		return deviceImageInfo == null?null : entity2so(deviceImageInfo);
	}
}
